// pages/inferioraList/inferioraOrder.js
var app = getApp()
Page({
  data: {
    statusType: ["已付款", "已退款", "库存"],
    currentType: 0,
    tabClass: ["", "", "", "", ""],
    bodyHeight:null,
    index:1,
    isFinish:false,
    orderList:[],
    selectIndex: 0,
    uid: '',
    title: '',
    kcData: {}
  },

  statusTap: function (e) {
    console.log(e);
    console.log(e.hasOwnProperty("currentTarget"))
    if (e && e.hasOwnProperty("currentTarget")) {
      this.setData({
        currentType: 's' + (e.currentTarget.dataset.index + 1)
      })
    } else {
      this.setData({
        currentType: e.currentType
      })
    }
   
    this.setData({
      orderList:[],
      isFinish:false,
      index:1,
    })
    this.getData();
    this.onShow();
  },
  orderDetail: function (e) {
    var orderId = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: "/pages/order-detail/order-detail?id=" + orderId + '&share=1'
    })
  },
  priceFilter(val){
    val = parseFloat(val).toFixed(2)
    return val
  },
  onLoad: function (e) {
    var that = this;
    that.setData({
      uid: e.uid,
      title: e.title
    })
    console.log(that.priceFilter('.00'))
    wx.hideShareMenu()
    if (app.globalData.iphone == true) { that.setData({ iphone: 'iphone' }) }
    that.setData({
      currentType: 's1'
    });
    console.log(e)
    that.statusTap({
      currentType: 's1'
    })   
  },
  onReady: function () {
    // 生命周期函数--监听页面初次渲染完成

  },
  getOrderStatistics: function () {
    var that = this;
    // wx.request({
    //   url: app.siteInfo.url + app.siteInfo.subDomain + '/order/statistics',
    //   data: { token: app.globalData.token },
    //   success: (res) => {
    //     wx.hideLoading();
    //     if (res.data.code == 0) {
    //       var tabClass = that.data.tabClass;
    //       if (res.data.data.count_id_no_pay > 0) {
    //         tabClass[0] = "red-dot"
    //       } else {
    //         tabClass[0] = ""
    //       }
    //       if (res.data.data.count_id_no_transfer > 0) {
    //         tabClass[1] = "red-dot"
    //       } else {
    //         tabClass[1] = ""
    //       }
    //       if (res.data.data.count_id_no_confirm > 0) {
    //         tabClass[2] = "red-dot"
    //       } else {
    //         tabClass[2] = ""
    //       }
    //       if (res.data.data.count_id_no_reputation > 0) {
    //         tabClass[3] = "red-dot"
    //       } else {
    //         tabClass[3] = ""
    //       }
    //       if (res.data.data.count_id_success > 0) {
    //         //tabClass[4] = "red-dot"
    //       } else {
    //         //tabClass[4] = ""
    //       }

    //       that.setData({
    //         tabClass: tabClass,
    //       });
    //     }
    //   }
    // })
  },
  logisticsTap(e){
    var orderId=e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/logistics/logistics?id='+orderId,
    })
  },
  getData:function(status,index){
    let _this=this;
    if( this.data.currentType == 's1' || this.data.currentType == 's2' ){
      if(this.data.isFinish){
        // wx.showToast({
        //   title: '没有更多了~',
        // })
        return
      }
      wx.showLoading({
        title: '加载中...',
      })
      app.get(`order/get_orders?CustId=${this.data.uid}&Status=${this.data.currentType}&page=${this.data.index}&size=20`,(res)=>{
        wx.hideLoading();
        if(res&&res.code=="0"){
          if(res.result.length>0){
            _this.setData({
              orderList:_this.data.orderList.concat(res.result),
              index:this.data.index+1
            });
          }else{          
            _this.setData({
              isFinish:true,
            })
            // wx.showToast({
            //   title: '没有更多了~',
            // })
          } 
        }
      })
    }else{
      app.get(`stock/get_sum_t_stock_record?CustId=${this.data.uid}`, res => {
        console.log(this.data.currentType)
        this.setData({
          kcData: res.result
        })
      })
    }
    
  },
  onShow: function (e) {
    // 获取订单列表
    // wx.showLoading();
    var that = this;
    // this.getOrderStatistics();

    // wx.request({
    //   url: app.siteInfo.url + app.siteInfo.subDomain + '/order/list',
    //   data: postData,
    //   success: (res) => {
		// 		console.log(res)
    //     wx.hideLoading();
    //     if (res.data.code == 0) {
    //       that.setData({
    //         orderList: res.data.data.orderList,
    //         logisticsMap: res.data.data.logisticsMap,
    //         goodsMap: res.data.data.goodsMap
    //       });
    //     } else {
    //       this.setData({
    //         orderList: null,
    //         logisticsMap: {},
    //         goodsMap: {}
    //       });
    //     }
    //   }
    // })
		// var winInfo = wx.getSystemInfo({
		// 	success: function (res) {
		// 		var windowHeight = res.windowHeight;
		// 		var statusBarHeight = res.statusBarHeight;
		// 		var titleBarHeight = 0
		// 		if (res.model.indexOf('iPhone') !== -1) {
		// 			titleBarHeight = 44
		// 		} else {
		// 			titleBarHeight = 48
		// 		}
		// 		var query = wx.createSelectorQuery();
		// 		query.select('.status-box').boundingClientRect()
		// 		query.exec((res) => {
		// 		  var listHeight = res[0].height; // 获取list高度
		// 			that.setData({ bodyHeight: windowHeight - statusBarHeight - titleBarHeight - listHeight });
		// 		})
				
			
		// 	}
		// });
  },
  onHide: function () {
    // 生命周期函数--监听页面隐藏

  },
  onUnload: function () {
    // 生命周期函数--监听页面卸载

  },
  onPullDownRefresh: function () {
    // 页面相关事件处理函数--监听用户下拉动作

  },
  onReachBottom: function () {
    // 页面上拉触底事件的处理函数

  }
})